<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>01条件渲染</title>
  <script src="../js/vue.js"></script>
  <style>
    h3 {
      color: red;
    }
  </style>
</head>
<body>
  <div id="app">
    <!-- 
      条件渲染
        1 v-if
          适用于无需频繁切换的场景
          不展示的DOM直接被移除
          v-if，v-else-if，v-else结构中间不能被打断
          可以搭配template组合使用

        2 v-show
          适用于会频繁切换的场景
          不展示的DOM依旧在dom树种，仅是通过样式隐藏起来了
          无法搭配template
     -->
    <h1>{{title}}</h1>
    <button @click="handleClick">click</button>
    <h3>v-show</h3>
    <div v-show="number === 1">Vue</div>
    <div v-show="number === 2">React</div>
    <div v-show="number === 3">Angular</div>
    <div v-show="number > 3">其他</div>
    <h3>v-if</h3>
    <div v-if="number === 1">Vue</div>
    <div v-if="number === 2">React</div>
    <div v-if="number === 3">Angular</div>
    <div v-if="number > 3">其他</div>
    <h3>v-else-if</h3>
    <div v-if="number === 1">Vue</div>
    <div v-else-if="number === 2">React</div>
    <div v-else-if="number === 3">Angular</div>
    <div v-else>其他</div>
    <h3>template</h3>
    <template v-if="number === 1">
      <div>Vue</div>
      <div>React</div>
      <div>Angular</div>
      <div>v-if</div>
    </template>
    <template v-show="number === 1">
      <div>Vue</div>
      <div>React</div>
      <div>Angular</div>
      <div>v-show</div>
    </template>
  </div>
  <script>
    new Vue({
      el: '#app',
      data() {
        return {
          title: '条件渲染',
          number: 0
        }
      },
      methods: {
        handleClick() {
          this.number++
        }
      }
    })
  </script>
</body>
</html>